package org.kommii.log;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


public class LogWriter {
	private static String[] names = {"admin_manager","user_manager","auth_manager",
										"admin_select","user_select","auth_select",
											"login","jsp_page"};
	private static Map<String,Logger> map = new HashMap<String,Logger>();
	static{
		String path = LogWriter.class.getClassLoader().getResource("").getPath();
		PropertyConfigurator.configure(path + "log4j.properties");
		int size = names.length;
		Logger logger = null;
		for(int i=0;i<size;i++){
			logger = Logger.getLogger(names[i]);
			map.put(names[i], logger);
		}
	}
	
	public static Logger getLogger(String name){
		return map.get(name);
	}
	
	public static void writeLog(String name,String uname,String param){
		Logger logger = getLogger(name);
		if(null!=logger){
			logger.info("----------------------- "+name+" start   -----------------------");
			if(null!=uname)
			logger.info(uname);
			logger.info(param);
			logger.info("----------------------- "+name+" end     -----------------------");
		}
	}
	
	public static void main(String[] args){
		LogWriter.writeLog(LogNames.user_select, "userid 1 ,usaername great, project!select","projectid:19,name:abc");
	}
	
}
